class Food {
    element: HTMLElement;

    constructor() {
        // 末尾 ! 表示100%确定有值
        this.element = document.getElementById('food')!;
    }
    get X() {
        return this.element.offsetLeft;
    }
    get Y() {
        return this.element.offsetTop;
    }
    change() {
        // 游戏界面是 300 * 300  所以食物生成的坐标是 [0,290px]
        let top = Math.round(Math.random() * 29) * 10;
        let left = Math.round(Math.random() * 29) * 10;

        this.element.style.left = left + 'px';
        this.element.style.top = top + 'px';
    }


}

export default Food;

// // 测试 食物生成
// const food = new Food();
// food.change();
// console.log(food.X, food.Y);
